package com.leo;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.DialogPane;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.text.Text;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.util.Duration;

/**
 * @ClassName DialogPaneDemo
 * @Description 提示框
 * @Author wangss
 * @date 2020.05.17 22:11
 * @Version 1.0
 */
public class DialogPaneDemo extends Application {
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(final Stage primaryStage) throws Exception {

        Button button = new Button("弹出对话框");
        button.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                final Stage stage = new Stage();

                DialogPane dialogPane = new DialogPane();
                dialogPane.setHeaderText("有内鬼");
                dialogPane.setContentText("这是内容");

                ImageView imageView = new ImageView("image/icon1.png");
                ImageView imageView1 = new ImageView(new Image("image/icon1.png", 100d, 100d, false, false));
                dialogPane.setGraphic(imageView1);

                dialogPane.getButtonTypes().add(ButtonType.APPLY);
                dialogPane.getButtonTypes().add(ButtonType.CLOSE);

                // 添加事件
                Button colse = (Button) dialogPane.lookupButton(ButtonType.CLOSE);
                colse.setOnAction(new EventHandler<ActionEvent>() {
                    @Override
                    public void handle(ActionEvent event) {
                        stage.close();
                        primaryStage.close();
                    }
                });

                // 增加扩展内容
                dialogPane.setExpandableContent(new Text("这是扩展内容"));
//                dialogPane.setExpanded(true);

                Scene scene = new Scene(dialogPane);

                stage.setScene(scene);
                stage.initOwner(primaryStage);
                stage.initStyle(StageStyle.UTILITY);
                stage.initModality(Modality.WINDOW_MODAL);
                stage.setTitle("这是弹出窗口");
                stage.setResizable(false);
                stage.setWidth(400d);
                stage.setHeight(300d);
                stage.show();

                ScheduledServiceDemo scheduledServiceDemo = new ScheduledServiceDemo(dialogPane, stage);
                // 什么时候启动
                scheduledServiceDemo.setDelay(Duration.millis(0d));
                // 间隔时间
                scheduledServiceDemo.setPeriod(Duration.millis(2000d));
                scheduledServiceDemo.start();
            }
        });

        AnchorPane ap = new AnchorPane();
        ap.setStyle("-fx-background-color: #09b6ff");
        ap.getChildren().addAll(button);

        Scene scene = new Scene(ap);
        primaryStage.setScene(scene);
        primaryStage.setTitle("TilePane");
        primaryStage.setWidth(600d);
        primaryStage.setHeight(600d);
        primaryStage.show();
    }
}
